{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "## 24.2 Single-source shortest paths in directed acyclic graphs"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 24.2-1\n",
    "\n",
    "> Run DAG-SHORTEST-PATHS on the directed graph of Figure 24.5, using vertex $r$ as the source."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "|\\|$r$|$s$|$t$|$x$|$y$|$z$|\n",
    "|:-:|:-:|:-:|:-:|:-:|:-:|:-:|\n",
    "|$d$|0|5|3|10|7|5|\n",
    "|$\\pi$|NIL|$r$|$r$|$t$|$t$|$t$|"
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 24.2-2\n",
    "\n",
    "> Suppose we change line 3 of DAG-SHORTEST-PATHS to read \n",
    "> \n",
    "> 3  __for__ the first $|V| - 1$ vertices, taken in topologically sorted order\n",
    "> \n",
    "> Show that the procedure would remain correct."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "The out-degree of the last vertex is 0."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 24.2-3\n",
    "\n",
    "> The PERT chart formulation given above is somewhat unnatural. In a more natural structure, vertices would represent jobs and edges would represent sequencing constraints; that is, edge $(u, v)$ would indicate that job $u$ must be performed before job $v$. We would then assign weights to vertices, not edges. Modify the DAG-SHORTEST- PATHS procedure so that it finds a longest path in a directed acyclic graph with weighted vertices in linear time."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$s.d = s.w$, $w(u, v) = v.w$."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "### 24.2-4\n",
    "\n",
    "> Give an efficient algorithm to count the total number of paths in a directed acyclic graph. Analyze your algorithm."
   ]
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": [
    "$s.num = 1$, $v.num = \\sum_{(u, v) \\in E} u.num$.\n",
    "\n",
    "Time: $\\Theta(V + E)$."
   ]
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.3"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
